<?php
/**
 * //w/w/w.s/h/u/o/t//u/p/u c/o/m  说/图/谱/源/码/分/享
 */
defined("IN_IA")or exit("Access Denied");
checklogin();  //验证是否登录
global $_W,$_GPC;
$uniacid=$_W['uniacid'];
$op=$_GPC['op'] ? $_GPC['op'] : "article_type";
if($op=='article_type'){
	$con=array('uniacid'=>$uniacid);
	$all=pdo_getall('cqkundian_farm_article_type',$con);
	$page=$_GPC['page'] ? $_GPC['page'] : 1;
	$pager=pagination($count,$page,10);
	$list=pdo_getall('cqkundian_farm_article_type',$con,'','','rank asc',array($page,10));
	include $this->template("web/article/article_type");
}
//资讯分类新增/编辑
if($op=='article_type_edit'){
	if(!empty($_GPC['id'])){
		$list=pdo_get('cqkundian_farm_article_type',array('uniacid'=>$uniacid,'id'=>$_GPC['id']));
	}
	include $this->template("web/article/article_type_edit");
}
//资讯分类保存
if($op=='article_type_save'){
	$data=array(
		'type_name'=>$_GPC['type_name'],
		'rank'=>$_GPC['rank'],
		'uniacid'=>$uniacid
	);
	if(empty($_GPC['id'])){
		$res=pdo_insert('cqkundian_farm_article_type',$data);
	}else{
		$res=pdo_update('cqkundian_farm_article_type',$data,array('uniacid'=>$uniacid,'id'=>$_GPC['id']));
	}
	if($res){
		message('操作成功',url('site/entry/article',array('m'=>'kundian_farm','op'=>'article_type')));die;
	}else{
		message('操作失败');die;
	}
}

//资讯分类删除
if($op=='article_type_delete'){
	$id=$_GPC['id'];
	$res=pdo_delete('cqkundian_farm_article_type',array('uniacid'=>$uniacid,'id'=>$_GPC['id']));
	echo $res ? json_encode(array('status'=>1)) :json_encode(array('status'=>2));die;
}

//资讯列表
if($op=='article_list'){
	$con=array('uniacid'=>$uniacid);
	$all=pdo_getall('cqkundian_farm_article',$con);
	$page=$_GPC['page'] ? $_GPC['page'] : 1;
	$pager=pagination($count,$page,10);
	$list=pdo_getall('cqkundian_farm_article',$con,'','','rank asc',array($page,10));
	for ($i=0; $i <count($list) ; $i++) { 
		$typeData=pdo_get('cqkundian_farm_article_type',array('id'=>$list[$i]['type_id'],'uniacid'=>$uniacid));
		$list[$i]['type_name']=$typeData['type_name'];
		$list[$i]['create_time']=date("Y-m-d H:i:s",$list[$i]['create_time']);
	}
	include $this->template('web/article/article_list');
}

//资讯新增/编辑
if($op=='article_list_edit'){
	if(!empty($_GPC['id'])){
		$list=pdo_get('cqkundian_farm_article',array('uniacid'=>$uniacid,'id'=>$_GPC['id']));
	}
	$typeData=pdo_getall('cqkundian_farm_article_type',array('uniacid'=>$uniacid));
	include $this->template('web/article/article_list_edit');
}

//资讯保存
if($op=='article_list_save'){
	$data=array(
		'title'=>$_GPC['title'],
		'type_id'=>$_GPC['type_id'],
		'cover'=>tomedia($_GPC['cover']),
		'content'=>$_GPC['content'],
		'uniacid'=>$uniacid,
		'rank'=>$_GPC['rank'],
		'create_time'=>time(),
		'view_count'=>$_GPC['view_count'],
	);
	if(empty($_GPC['id'])){
		$res=pdo_insert('cqkundian_farm_article',$data);
	}else{
		$res=pdo_update('cqkundian_farm_article',$data,array('uniacid'=>$uniacid,'id'=>$_GPC['id']));
	}
	if($res){
		message('操作成功',url('site/entry/article',array('m'=>'kundian_farm','op'=>'article_list')));
	}else{
		message('操作失败');die;
	}
}

//资讯删除
if($op=='article_list_delete'){
	$id=$_GPC['id'];
	$res=pdo_delete('cqkundian_farm_article',array('uniacid'=>$uniacid,'id'=>$id));
	echo $res ? json_encode(array('status'=>1)) : json_encode(array('status'=>2));die;
}
